package com.card.hwatt.assembler;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.card.hwatt.core.ObjectUtil;
import com.card.hwatt.dto.*;

/**
 * 个人考勤
 * @author Administrator
 *
 */
public final class PrivateWorkSumAssembler {

	public static Map<String, Object> convert(List<MonthWork> list) {
		List<PrivateWorkSum> rows = new ArrayList<PrivateWorkSum>();

		PrivateWorkSum footer = new PrivateWorkSum();
		footer.month = "汇总：";

		int i = 0;
		for (MonthWork monthWork : list) {
			PrivateWorkSum privateWorkSum = new PrivateWorkSum();
			ObjectUtil.fieldCopy(monthWork, privateWorkSum);

			privateWorkSum.month = (++i) + "月";
			privateWorkSum.id = i;
			rows.add(privateWorkSum);

			if (monthWork.leave != null) {
				privateWorkSum.leave = monthWork.leave;
			}
			if (monthWork.day != null) {
				privateWorkSum.day = monthWork.day;
			}
			if (monthWork.night != null) {
				privateWorkSum.night = monthWork.night;
			}
			if (monthWork.full != null) {
				privateWorkSum.full = monthWork.full;
			}
			if (monthWork.early != null) {
				privateWorkSum.early = monthWork.early;
			}
			if (monthWork.late != null) {
				privateWorkSum.late = monthWork.late;
			}
			if (monthWork.holiday != null) {
				privateWorkSum.holiday = monthWork.holiday;
			}

			footer.leave += privateWorkSum.leave;
			footer.day += privateWorkSum.day;
			footer.night += privateWorkSum.night;
			footer.full += privateWorkSum.full;
			footer.early += privateWorkSum.early;
			footer.late += privateWorkSum.late;
			footer.holiday += privateWorkSum.holiday;
		}

		Map<String, Object> result = new HashMap<String, Object>();
		result.put("rows", rows);
		result.put("total", rows.size());
		result.put("footer", new PrivateWorkSum[] { footer });
		return result;
	}
}
